package com.ruoyi.train.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.train.domain.TrainPlan;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.ruoyi.train.service.ITrainPlanService;


/**
 * 培训计划Controller
 * 
 * @author wusihao
 * @date 2023-03-16
 */
@Api(tags = "培训计划表")
@RestController
@CrossOrigin
@RequestMapping("/train/plan")
public class TrainPlanController extends BaseController
{
    @Autowired
    private ITrainPlanService trainPlanService;

    /**
     * 查询培训计划列表
     */
    @ApiOperation("查询培训计划表")
    @GetMapping("/list")
    public TableDataInfo list(TrainPlan trainPlan)
    {
        startPage();
        List<TrainPlan> list = trainPlanService.selectTrainPlanVoList(trainPlan);
        return getDataTable(list);
    }

    /**
     * 导出培训计划列表
     */
    @ApiOperation("导出培训计划")
    @Log(title = "培训计划", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TrainPlan trainPlan)
    {
        List<TrainPlan> list = trainPlanService.selectTrainPlanList(trainPlan);
        ExcelUtil<TrainPlan> util = new ExcelUtil<TrainPlan>(TrainPlan.class);
        util.exportExcel(response, list, "培训计划数据");
    }

    /**
     * 获取培训计划详细信息
     */
    @ApiOperation("获取培训计划详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(trainPlanService.selectTrainPlanById(id));
    }

    /**
     * 新增培训计划
     */
    @ApiOperation("新增培训计划")
    @Log(title = "培训计划", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TrainPlan trainPlan)
    {
        return toAjax(trainPlanService.insertTrainPlan(trainPlan));
    }

    /**
     * 修改培训计划
     */
    @ApiOperation("修改培训计划")
    @Log(title = "培训计划", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TrainPlan trainPlan)
    {
        return toAjax(trainPlanService.updateTrainPlan(trainPlan));
    }

    /**
     * 删除培训计划
     */
    @ApiOperation("删除培训计划")
    @Log(title = "培训计划", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(trainPlanService.deleteTrainPlanByIds(ids));
    }

    /*提交培训计划*/
    @ApiOperation("提交培训计划")
    @PutMapping("/{trainId}")
    @Log(title = "培训计划", businessType = BusinessType.UPDATE)
    public AjaxResult sumbit(@PathVariable Long trainId) {
        return toAjax(trainPlanService.submitTrain(trainId));
    }

    /*得到级联选择器*/
    @ApiOperation("得到级联选择器")
    @GetMapping("/getDictDateByPid/{pid}")
    @Log(title = "培训计划", businessType = BusinessType.UPDATE)
    public TableDataInfo getDictDateByPid(@PathVariable Long pid) {
        return getDataTable(trainPlanService.getDictDateByPid(pid));
    }

}
